<!-- *************
 *@description: 登录页面
 *@author:rennan
 *@date: 2023-03-29 18:52:33
 *@version: V1.0.0
 ************ -->

<template>
  <div class="login_container">
    <div class="bg"></div>
    <div class="header">
      <div class="title">
        家政服务预约云平台
      </div>
    </div>
    <!-- 中间部分 -->
    <div class="center">
      <!-- 登录表单 -->
      <div class="form">
        <el-form ref="loginForm" class="login_form" :model="loginForm" :rules="loginRules">
          <div style="text-align:center;height:60px;line-height:60px;font-weight:bold">用户名密码登录</div>
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="请输入用户名" type="text" ref="username"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" palceholder="请输入密码" show-password>
            </el-input>
          </el-form-item>
          <div>
            <el-button :loading="loading" style="width:100%;" @click="handleLogin">登录</el-button>
          </div>
        </el-form>
      </div>
    </div>
    <div class="footer">
      包头师范
    </div>
  </div>
</template>
 
<script>
  import utils from '@/utils/utils.js'
  import {login} from '@/api/user.js'
  export default{
    data(){
      return {
        loading:false,
        loginForm:{
          username:'',
          password:''
        },
        loginRules:{
          username:[{required:true,trigger:'blur',message:'用户名不能为空'}],
          password:[{required:true,trigger:'blur',message:'密码不能为空'}]
        }
      }
    },
    methods:{
      handleLogin(){
        this.loading = true
        // const jsonLofinForm = JSON.stringify(this.loginForm)
        login(this.loginForm).then(res=>{
          //请求成功之后，保存token  跳转路由到首页
          utils.setToken('token',res.token)
          this.loading = false
          this.$router.replace('/admin')
        }).catch(err=>{
          this.loading = false
        })
        // instance.post('/user/login',this.loginForm).then(res=>{
        //   if(res.status == 200){
        //     if(res.data.status == 2000){
        //       utils.showSuccess(res.data.message)
        //       // 保存token
        //       utils.setToken(res.data.token)
        //       this.$router.replace('/admin')
        //     }
        //   }else{
        //     utils.showWarning('登录失败')
        //   }
        // }).catch(err=>{
        //   console.log(err);
        // })
      }
    }
  }
</script>
 
<style lang="less" scoped>
 .login_container {
  position: absolute;
  width: 100%;
  top: 0;
  bottom: 0;
  background-color: #f4f4f4;
  overflow: hidden;
  .bg{
    height: 400px;
    background-color: #4fbc8d;
    position: absolute;
    width: 3000px;
    top: -100px;
    right: -200px;
    transform: rotate(10deg);
  }
  .header{
    height: 300px;
    background-color: #4fbc8d;
    position: relative;
    color: #fff;
    .title{
      text-align: center;
      position: absolute;
      bottom: 150px;
      width: 100%;
      font-size: 2em;
    }
  }
  .center{
    box-sizing: border-box;
    position: relative;
    top: -100px;
    background-color: #ffffff;
    width: 500px;
    margin: 0 auto;
    border-radius: 5px;
    padding: 2em;
    box-shadow: 0 0 10px #ccc;
  }
  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    line-height: 3em;
    text-align: center;
    font-size: 12px;
    font-weight: bold;
    background-color: #ffffff;
  }
 }
 </style>